package com.am.mosl.cityandroid.widget;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.ColorDrawable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;

import com.am.mosl.cityandroid.R;


import java.io.Serializable;

/**
 * Created by mosl on 14-7-6.
 */
public class SharePopWindow extends PopupWindow {

    private View mPopShare;
    private Activity activity;
    private ShareCallBack callBack;

    public SharePopWindow(Activity context, final View.OnClickListener itemsOnClick, final ShareCallBack shareCallBack){

        super(context);
        this.activity=context;
        this.callBack=shareCallBack;

        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mPopShare= inflater.inflate(R.layout.pop_share, null);

        View weix = mPopShare.findViewById(R.id.weix);
        weix.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shareCallBack.share(2); //微信
                dismiss();
            }
        });

        View wexcircle = mPopShare.findViewById(R.id.wexcircle);
        wexcircle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shareCallBack.share(3);
                dismiss();
            }
        });

        View sinaShare = mPopShare.findViewById(R.id.weibo);
        sinaShare.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shareCallBack.share(0);
                dismiss();
            }
        });
        View qqZone = mPopShare.findViewById(R.id.qq_zone);
        qqZone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shareCallBack.share(1);
                dismiss();
            }
        });
        this.setContentView(mPopShare);

        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        //设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        //设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        //设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);
        BrightButton btn_cancel=(BrightButton)mPopShare.findViewById(R.id.btn_cancle);
        btn_cancel.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                //销毁弹出框
                dismiss();
            }
        });
        mPopShare.setOnTouchListener(new View.OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {

                int height = mPopShare.findViewById(R.id.pop_layout).getTop();
                int y = (int) event.getY();
                Log.d("haha", height + "---" + y);
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    if (y < height) {
                        dismiss();
                    }
                }
                return true;
            }
        });

    }



    public interface ShareCallBack{
        public void share(int type);
    }
}
